package com.df.resources.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.alibaba.nacos.client.naming.NacosNamingService;
import com.df.resources.common.GatewayInstancesManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@RestController
public class CheckResourceController {



    @NacosValue(value = "${test.str}")
    private String testStr;

    @RequestMapping("gatewayList")
    public String getGateWayList(){
        Instance oneInstance = GatewayInstancesManager.getOneInstance();
        if(oneInstance==null){
            return "";
        }
        return oneInstance.getIp()+":"+oneInstance.getMetadata().get("gate-way-port");
    }

    @RequestMapping("checkResource")
    public void checkResource(){
        //TODO
        // 1.检查资源文件，扫描出要更新的文件名返回前端【前端有addressable技术，这一步可能会去掉】
        // 2.从注册中心获取网关列表，负载均衡选取一个返回给客户端，如果都不健康，返回排队或服务器繁忙的信息
    }
}
